<?php

namespace App\Http\Controllers\AjaxRequest;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Input;
use Redirect;

class submitInfocontroller extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  Request  $request
     * @return Response
     */
    public function store(Request $request)
    {
        $userId =     $_SERVER['HTTP_REFERER'];
        $id = explode('?',$userId);
        $userid = explode('=', $id[1]);
         $I_Name =  $request->input('I_Name');
         $gender = $request->input('gender');
         $I_tel =  $request->input('I_tel');
         $I_Area = $request->input('I_Area');
         $I_Email =  $request->input('I_Email');
         
         $json_arr = array("userid"=> $userid[1],"realname"=>$I_Name,"gender"=>$gender, "cellphone"=>$I_tel,"email"=>$I_Email,"area"=>$I_Area,);
       //  $json_obj = json_encode($json_arr);

         $o="";
        foreach ($json_arr as $k=>$v)
       {
            $o.= "$k=".urlencode($v)."&";
        }
      $json_data=substr($o,0,-1);
      $url =  "192.168.0.21:8080/test/user/info";
      $ch = curl_init();
      curl_setopt($ch,CURLOPT_URL,$url); /*获取URL的内容*/
      //do a put
       curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
       curl_setopt($ch,CURLOPT_POST,true);
       curl_setopt($ch,CURLOPT_POSTFIELDS,$json_data);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);/*获取的内容不输出*/
       $content = curl_exec($ch);/*输出获取的内容*/
        curl_close($ch);
        $obj=json_decode($content);
       if(empty($obj->error)){
            return Redirect::to('Reg_result');
           //header("Location:/Reg_result");
          //  exit(0);
       }else{
          return Redirect::back()->withInput()->withErrors( $obj->error);
         //   echo $obj->error;
       }
      /*return response()->json($arrayName = array('result' => $content));*/
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  Request  $request
     * @param  int  $id
     * @return Response
     */
    public function update(Request $request, $id)
    {
        
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        //
    }
}
